#!/bin/bash

path="./git"
 
function mkrepos()
{
    if [ ! -d "$path" ]; then
        mkdir "$path"
    fi
    
    cd $path    
}

function git8500()
{
    path="./soft"
    pathbak="./softbak"
  
    if [ -d "$pathbak" ]; then
        rm -rf "$pathbak"
    fi

    mv "$path" "$pathbak"
    
    git clone ssh://wangxiaobin@192.168.193.27:29418/8500.git ./soft

    cp ../../shell/mk ./soft
}

function cooltool()
{
    path="./cooltool"
    pathbak="./cooltoolbak"
   
    if [ -d "$pathbak" ]; then
        rm -rf "$pathbak"
    fi

    mv "$path" "$pathbak"

    git clone ssh://wangxiaobin@192.168.193.27:29418/cooltools.git ./cooltool
}

function help()
{
    echo "***********************************************************************"
    echo -e "*     \e[1;31m Usage describtion as following:\e[0m                                *"
    echo -e "*     \e[1;31m -e: clone project 8500 to /home/username/projects/git/soft\e[0m     *"
    echo -e "*     \e[1;31m -c: clone project cooltool to ....../projects/git/cooltool\e[0m     *"
    echo -e "*     \e[1;31m -h: look up detail information about command clone\e[0m             *"
    echo "***********************************************************************"
}

function main()
{
    mkrepos

    para=$1
    
    if [ "$para" = "-e" ]; then
        git8500
    elif [ "$para" = "-c" ]; then
        cooltool
    else
        help
    fi
}

for para in "$*"
do
    main ${para}
done
